package com.itcast.donkey.adapters;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.itcast.donkey.R;
import com.itcast.donkey.modles.ToolBoxModles;

import java.util.List;

/**
 * Created by lanouhn on 16/9/5.
 */
public class ToolExpandListViewAdapter extends BaseExpandableListAdapter {
    private Context context;
    private List<ToolBoxModles.DestinationsBean> modlesList;

    public ToolExpandListViewAdapter(Context context, List<ToolBoxModles.DestinationsBean> modlesList) {
        this.context = context;
        this.modlesList = modlesList;
    }

    @Override
    public int getGroupCount() {
        return modlesList.size();
    }

    @Override
    public int getChildrenCount(int groupPosition) {
        return modlesList.get(groupPosition).getChildren().size();
    }

    @Override
    public Object getGroup(int groupPosition) {
        return modlesList.get(groupPosition);
    }

    @Override
    public Object getChild(int groupPosition, int childPosition) {
        return modlesList.get(groupPosition).getChildren().get(childPosition);
    }

    @Override
    public long getGroupId(int groupPosition) {
        return groupPosition;
    }

    @Override
    public long getChildId(int groupPosition, int childPosition) {
        return childPosition;
    }

    @Override
    public boolean hasStableIds() {
        return false;
    }

    @Override
    public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
        View view = View.inflate(context, R.layout.item_tool_overseas, null);
        TextView tvItemToolAreaname;
        ImageView ivItemToolDown;
        LinearLayout linItemToolRecycler;

        tvItemToolAreaname = (TextView) view.findViewById(R.id.tv_item_tool_areaname);
        ivItemToolDown = (ImageView) view.findViewById(R.id.iv_item_tool_down);
        linItemToolRecycler = (LinearLayout) view.findViewById(R.id.lin_item_tool_recycler);

        tvItemToolAreaname.setText(modlesList.get(groupPosition).getName_zh_cn());

        if (isExpanded) {
            ivItemToolDown.setBackgroundResource(R.mipmap.icon_destination_brief_title_arrows_up);
        } else {
            ivItemToolDown.setBackgroundResource(R.mipmap.icon_destination_brief_title_arrows_down);
        }
        return view;
    }

    @Override
    public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
        View view = View.inflate(context, R.layout.item_tool_showarea, null);

        TextView tvItemInName = (TextView) view.findViewById(R.id.tv_item_in_name);
        tvItemInName.setText(modlesList.get(groupPosition).getChildren().get(childPosition).getName_zh_cn());
        return view;
    }

    @Override
    public boolean isChildSelectable(int groupPosition, int childPosition) {
        return true;
    }
}
